package com.team.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.dao.NewsMapper;
import com.team.entity.News;
import com.team.service.NewsUpAndDownService;
import com.team.vo.Result;
import com.team.vo.SearchContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author keluoyisi
 * @program: seven
 * @description: 上下文的业务成实现
 * @date 2022-10-18 00:48:28
 */
@Service
public class NewsUpAndDownServiceImpl implements NewsUpAndDownService {
    @Autowired
    private NewsMapper newsMapper;
    /**
     * @param :
     * @return Result
     * @description 获取到所有的新闻
     */
    @Override
    public Result selectAllNews(int currentPage, int pageSize, SearchContent searchContent) {

        if (searchContent.getTime()!=null){
            searchContent.setBeginDate(searchContent.getTime()[0]);
            searchContent.setEndDate(searchContent.getTime()[1]);
        }

        if (searchContent.getKind()!=null){
            if (searchContent.getKind().equals("医院新闻")){
                searchContent.setKid(1);
            }
            else if(searchContent.getKind().equals("通知公告")){
                searchContent.setKid(2);
            }
            else {
                searchContent.setKid(3);
            }
        }
        PageHelper.startPage(currentPage,pageSize);
        System.out.println(searchContent);
        List<News> list = newsMapper.selectAllNews(searchContent);
        System.out.println(list);
        PageInfo<News> empPageInfo = new PageInfo<>(list);
        return new Result(200,"查询成功",empPageInfo);
    }

    /**
     * @param id:
     * @param status:
     * @return Result
     * @description 修改新闻的上下架
     */
    @Override
    public Result upUpdate(int id,int status) {
        if (status==1||status==4){
            status=2;
        }
        else{
            status=4;
        }
        System.out.println(id);
        System.out.println(status);
        newsMapper.updateStatus(id,status);
        return new Result(200,"修改成功");
    }

    /**
     * @param id:
     * @param uppid:
     * @return Result
     * @description 修改新闻的置顶和取消置顶
     */
    @Override
    public Result topUpdate(int id,int uppid) {
        if (uppid==5){
            uppid=6;
        }
        else {
            uppid=5;
        }
        System.out.println(id);
        System.out.println(uppid);
        newsMapper.updateUppid(id,uppid);
        return new Result(200,"修改成功");
    }
}
